package com.xoms.pad.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xoms.pad.aspect.datasource.DataSourceSwitcher;
import com.xoms.pad.cache.dao.ProCategoryCache;
import com.xoms.pad.controller.res.bean.RProductBean;
import com.xoms.pad.model.ProductBean;
import com.xoms.pad.persist.dao.ProCategoryDao;
import com.xoms.pad.persist.dao.ProductDao;
import com.xoms.pad.persist.impl.ProCategoryImpl;
import com.xoms.pad.persist.impl.ProductImpl;
import com.xoms.pad.service.ProductService;

@Service
public class ProductServiceImpl implements ProductService {

	Logger logger = Logger.getLogger(this.getClass());

	@Autowired
	ProCategoryCache proCategoryCacheImpl;

	@Autowired
	ProductImpl productImpl;

	@Autowired
	ProductDao productDao;
	
	@Autowired
	ProCategoryImpl proCategoryImpl;
	

	@Autowired
	ProCategoryDao proCategoryDao;

	@Override
	public List<RProductBean>  getProducts(String accid,String pid,String name) {
		//获取数据源
		DataSourceSwitcher.setDataSourceType(DataSourceSwitcher.DATA_SOURCE_XOMS);
		//通过Pid去查商品信息
		List<ProductBean> proList = new  ArrayList<>();
		logger.info("accid ================= is:" + accid);
		proList = productImpl.selectProducts(accid,pid,name);
		if (proList == null || proList.size()<=0) {
			return null;
		}
		List<RProductBean> products = new ArrayList<>();
		for(ProductBean product: proList){
			RProductBean rProductBean = new RProductBean();
			rProductBean.setPid(product.getPid());
			rProductBean.setName(product.getName());
			rProductBean.setCategoryId(product.getCategoryId());
			rProductBean.setCategoryArr(product.getCategoryArr());
			rProductBean.setSpecs(product.getSpecs());
			rProductBean.setUnit(product.getUnit());
			rProductBean.setRemark(product.getRemark());
			rProductBean.setCreateTime(product.getCreateTime());
			rProductBean.setStartTime(product.getStartTime());
			rProductBean.setEndTime(product.getEndTime());
			rProductBean.setImgUrl(product.getImgUrl());
			rProductBean.setProductNo(product.getProductNo());
			rProductBean.setProductBar(product.getProductBar());
			rProductBean.setPrice(product.getPrice());
			rProductBean.setSaleStatus(product.getSaleStatus());
			rProductBean.setUnitId(product.getUnitId());
			rProductBean.setAntiPrice(product.getAntiPrice());
			rProductBean.setInitial(product.getInitial());
			rProductBean.setMaxNum(product.getMaxNum());
			rProductBean.setWarnNum(product.getWarnNum());
			rProductBean.setStore(product.getStore());
			products.add(rProductBean);
		}
		return products;
	}




	


}
